package com.arui.yygh.user.api;

import com.arui.yygh.common.result.Result;
import com.arui.yygh.common.utils.AuthContextHolder;
import com.arui.yygh.model.acl.User;
import com.arui.yygh.model.user.UserInfo;
import com.arui.yygh.user.service.UserInfoService;
import com.arui.yygh.vo.user.LoginVo;
import com.arui.yygh.vo.user.UserAuthVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/api/user")
public class UserInfoApiController  {
    @Autowired
    private UserInfoService userInfoService;
    //用户手机号登录接口
    @PostMapping("/login")
    public Result login(@RequestBody LoginVo loginVo){
        Map<String,Object> map =  userInfoService.loginUser(loginVo);
        return Result.ok(map);
    }
    //用户认证
    @PostMapping("/auth/userAuth")
    public Result userAuth(@RequestBody UserAuthVo userAuthVo, HttpServletRequest request){
        //传递两个参数，第一个参数，用户id，第二个参数认证数据vo对象

        userInfoService.userAuth(AuthContextHolder.getUserId(request),userAuthVo);

        return Result.ok();
    }

    //根据用户id获取用户信息，认证信息
    @GetMapping("/auth/getUserInfo")
    public Result getUserInfo(HttpServletRequest request){

        UserInfo userInfo = userInfoService.getById(AuthContextHolder.getUserId(request));
        return Result.ok(userInfo);
    }
}
